
Partial Class DashboardControls_EmployeeFiles
    Inherits System.Web.UI.UserControl
    Implements IDashBoard

    Private titleLabelString As String = ""
    Dim pageSizeValue As Integer

    Protected Property GridViewSortDirection() As String
        Get
            If ViewState("SortDirection") Is Nothing Then
                ViewState("SortDirection") = SortDirection.Ascending
            End If
            Return CType(ViewState("SortDirection"), SortDirection)
        End Get
        Set(ByVal value As String)
            ViewState("SortDirection") = value
        End Set
    End Property

    Public Property SortDirection() As System.Web.UI.WebControls.SortDirection Implements IDashBoard.SortDirection
        Get
            Return EmployeeFilesGridView.SortDirection
        End Get
        Set(ByVal value As System.Web.UI.WebControls.SortDirection)

        End Set
    End Property

    Public Property PageNumber() As Integer Implements IDashBoard.PageNumber
        Get
            Return Me.EmployeeFilesGridView.PageIndex
        End Get
        Set(ByVal value As Integer)
            Me.EmployeeFilesGridView.PageIndex = value
        End Set
    End Property
    Public Property PageSize() As Integer Implements IDashBoard.PageSize
        Get
            If Not IsNothing(Me.EmployeeFilesGridView) Then
                If Me.EmployeeFilesGridView.AllowPaging Then
                    Return Me.EmployeeFilesGridView.PageSize
                Else
                    Return -1
                End If
            Else
                Return pageSizeValue
            End If
        End Get
        Set(ByVal value As Integer)
            If Not IsNothing(Me.EmployeeFilesGridView) Then
                If value > -1 Then
                    Me.EmployeeFilesGridView.PageSize = value
                    Me.EmployeeFilesGridView.AllowPaging = True
                Else
                    Me.EmployeeFilesGridView.AllowPaging = False
                End If
                Me.NumberOfRowsDropDownList.SelectedValue = value.ToString()
            End If
            pageSizeValue = value
        End Set
    End Property

    Public Property SortField() As String Implements IDashBoard.SortField
        Get
            Return Me.EmployeeFilesGridView.SortExpression
        End Get
        Set(ByVal value As String)

        End Set
    End Property


    Public Property Title() As String Implements IDashBoard.Title
        Get
            If Me.TitleLabel IsNot Nothing Then
                Return TitleLabel.Text
            Else
                Return titleLabelString
            End If
        End Get
        Set(ByVal value As String)
            If TitleLabel IsNot Nothing Then
                TitleLabel.Text = value
            End If
            titleLabelString = value
        End Set
    End Property

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Not Me.IsPostBack Then
            AddHandler NumberOfRowsDropDownList.SelectedIndexChanged, AddressOf NumberOfRowsDropDownList_SelectedIndexChanged
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not String.IsNullOrEmpty(titleLabelString) Then
            Me.TitleLabel.Text = titleLabelString
        End If
        If pageSizeValue > 0 Then
            Me.PageSize = pageSizeValue
        End If

        If Not Me.IsPostBack Then
            GridViewSettingController.SetGridViewValues(Me, 5, "LastName", WebControls.SortDirection.Ascending)
            Me.BindGrid()
        End If
    End Sub

    Protected Sub NumberOfRowsDropDownList_SelectedIndexChanged(ByVal sender As Object, _
                                                                ByVal e As System.EventArgs) _
                                                                Handles NumberOfRowsDropDownList.SelectedIndexChanged

        If NumberOfRowsDropDownList.SelectedValue = "-1" Then
            Me.EmployeeFilesGridView.AllowPaging = False
        Else
            EmployeeFilesGridView.AllowPaging = True
            EmployeeFilesGridView.PageSize = NumberOfRowsDropDownList.SelectedValue
            EmployeeFilesGridView.PageIndex = 0
        End If

        Me.BindGrid()

    End Sub

    Public Sub BindGrid() Implements IDashBoard.BindGrid

        If Request.QueryString("UserId") IsNot Nothing Then
            Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Request.QueryString("UserId"), "LastName", True)
        Else
            Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Session("CurrentUserId"), "LastName", True)
        End If

        If Me.NumberOfRowsDropDownList.SelectedValue <> "-1" Then
            Me.EmployeeFilesGridView.PageSize = Me.NumberOfRowsDropDownList.SelectedValue
        End If
        Me.EmployeeFilesGridView.DataBind()
        GridViewSettingController.SaveSetting(Me)

    End Sub

    Protected Sub EmployeeFilesGridView_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles EmployeeFilesGridView.DataBound
        AccessibilityController.AddImageToSortableGridHeaders(EmployeeFilesGridView)
    End Sub

    Protected Sub grvEmployeeFiles_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles EmployeeFilesGridView.PageIndexChanging
        Me.PageNumber = e.NewPageIndex
        Me.BindGrid()
    End Sub

    Public Sub LoadControl1(ByVal sender As Object, ByVal e As System.EventArgs) Implements IDashBoard.LoadControl
        Me.Page_Load(sender, e)
    End Sub

    Protected Sub EmployeeFilesGridView_Sorting(ByVal sender As Object, _
                                                     ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) _
                                                     Handles EmployeeFilesGridView.Sorting

        Dim sortField As String = e.SortExpression
        If sortField.Equals("LastName") Then
            sortField = "LastName,FirstName"
        End If

        If GridViewSortDirection = SortDirection.Ascending Then
            GridViewSortDirection = SortDirection.Descending
            If Request.QueryString("UserId") IsNot Nothing Then
                Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Request.QueryString("UserId"), sortField, False)
            Else
                Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Session("CurrentUserId"), sortField, False)
            End If
        Else
            GridViewSortDirection = SortDirection.Ascending
            If Request.QueryString("UserId") IsNot Nothing Then
                Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Request.QueryString("UserId"), sortField, True)
            Else
                Me.EmployeeFilesGridView.DataSource = Cdm.DataCore.Custom.ParticipantDisplay.ListByEmployeeUserID(Session("CurrentUserId"), sortField, True)
            End If
        End If

        If Me.NumberOfRowsDropDownList.SelectedValue <> -1 Then
            Me.EmployeeFilesGridView.PageSize = Me.NumberOfRowsDropDownList.SelectedValue
        End If
        Me.EmployeeFilesGridView.DataBind()
        GridViewSettingController.SaveSetting(Me)

    End Sub

    Protected Sub EmployeeFilesGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
End Class
